package com.azxcrm.project.system.customer.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.azxcrm.common.utils.StringUtils;
import com.azxcrm.common.utils.security.ShiroUtils;
import com.azxcrm.project.system.customer.dao.ICustomerClueDao;
import com.azxcrm.project.system.customer.domain.CustomerClue;
import com.azxcrm.project.system.customer.service.ICustomerClueService;

/**
 * 客户线索 服务层实现
 * 
 * @author Dustyone
 * @date 2018-09-05
 */
@Service
public class CustomerClueServiceImpl implements ICustomerClueService {
	@Autowired
	private ICustomerClueDao customerClueDao;
	/**
	 * 查询客户线索信息
	 * 
	 * @param clueId 客户线索ID
	 * @return 客户线索信息
	 */
	@Override
	public CustomerClue selectCustomerClueById(Integer clueId) {
		return customerClueDao.selectCustomerClueById(clueId);
	}

	/**
	 * 查询客户线索列表
	 * 
	 * @param customerClue 客户线索信息
	 * @return 客户线索集合
	 */
	@Override
	public List<CustomerClue> selectCustomerClueList(CustomerClue customerClue) {
		return customerClueDao.selectCustomerClueList(customerClue);
	}

	/**
	 * 新增客户线索
	 * 
	 * @param customerClue 客户线索信息
	 * @return 结果
	 */
	@Override
	public int insertCustomerClue(CustomerClue customerClue) {
		return customerClueDao.insertCustomerClue(customerClue);
	}

	/**
	 * 修改客户线索
	 * 
	 * @param customerClue 客户线索信息
	 * @return 结果
	 */
	@Override
	public int updateCustomerClue(CustomerClue customerClue) {
		return customerClueDao.updateCustomerClue(customerClue);
	}

	/**
	 * 保存客户线索
	 * 
	 * @param customerClue 客户线索信息
	 * @return 结果
	 */
	@Override
	public int saveCustomerClue(CustomerClue customerClue) {
		Integer clueId = customerClue.getClueId();
		int rows = 0;
		if (StringUtils.isNotNull(clueId)) {
			rows = customerClueDao.updateCustomerClue(customerClue);
		} else {
			customerClue.setCreateBy(ShiroUtils.getLoginName());
			customerClue.setCluePrincipal(ShiroUtils.getUserId().intValue());
			rows = customerClueDao.insertCustomerClue(customerClue);
		}
		return rows;
	}

	/**
	 * 删除客户线索信息
	 * 
	 * @param clueId 客户线索ID
	 * @return 结果
	 */
	@Override
	public int deleteCustomerClueById(Integer clueId) {
		return customerClueDao.deleteCustomerClueById(clueId);
	}

	/**
	 * 批量删除客户线索对象
	 * 
	 * @param clueIds 需要删除的数据ID
	 * @return 结果
	 */
	@Override
	public int batchDeleteCustomerClue(Integer[] clueIds) {
		return customerClueDao.batchDeleteCustomerClue(clueIds);
	}

	/**
	 * 通过手机查询客户是否存在
	 *
	 * @param customerCellphone 客户手机号
	 * @return 客户线索信息
	 */
	@Override
	public List<CustomerClue> selectCustomerClueByPhone(String customerCellphone) {
		return customerClueDao.selectCustomerClueByPhone(customerCellphone);
	}
	
	/**
	 * 统计线索客户总数
	 * @return 线索客户总数
	 */
	@Override
	public int customerSumCount() {
		return customerClueDao.customerSumCount();
	}
	

}
